import React, { useEffect } from 'react'
import { Image, StyleSheet, View } from 'react-native'
import { useNavigation } from '@react-navigation/native';
import { StackNavigationProp } from '@react-navigation/stack';

import icon_logo_main from '../../assets/icon_main_logo.png';
import { load } from '../../utils/Storage';

export default function Welcome() {
  const navigation = useNavigation<StackNavigationProp<any>>()

  const getUserInfo = async() => {
    const userInfo = await load('userInfo')
    if(userInfo && JSON.parse(userInfo)){
      toHome()
    }else{
      toLogin()
    }
  }

  const toLogin = () => {
    navigation.replace('Login')
  }
  const toHome = () => {
    navigation.replace('MainTab')
  }

  useEffect(() => {
    setTimeout(() => {
      getUserInfo()
      // toLogin()
    }, 1000);
  }, [])

  return (
    <View style={styles.root}>
      <Image style={styles.image} source={icon_logo_main} />

    </View>
  )
}

const styles = StyleSheet.create({
  root: {
    width: '100%',
    height: '100%',
    backgroundColor: '#fff',
    flexDirection: 'column',
    alignItems: 'center'
  },
  image: {
    width: 200,
    resizeMode: 'contain',
    marginTop: 60
  }
})
